<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>163邮箱邮件通知功能配置 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="第一阶段：在163邮箱网页端获取“授权码”这是所有终端操作的前提，目的是获取一个用于第三方客户端登录的专用密码。  登录邮箱：在浏览器中访问 mail.163.com 并登录您的账户。 进入设置：点击页面顶部的 “设置” -&gt; “POP3&#x2F;SMTP&#x2F;IMAP”。 开启服务：确保 IMAP&#x2F;SMTP服务 这一项是 “已开启” 状态。 获取授权码：点击“授权码”管理，根据提示">
<meta property="og:type" content="article">
<meta property="og:title" content="163邮箱邮件通知功能配置">
<meta property="og:url" content="http://example.com/2025/07/30/163%E9%82%AE%E7%AE%B1%E9%82%AE%E4%BB%B6%E9%80%9A%E7%9F%A5%E5%8A%9F%E8%83%BD%E9%85%8D%E7%BD%AE/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="第一阶段：在163邮箱网页端获取“授权码”这是所有终端操作的前提，目的是获取一个用于第三方客户端登录的专用密码。  登录邮箱：在浏览器中访问 mail.163.com 并登录您的账户。 进入设置：点击页面顶部的 “设置” -&gt; “POP3&#x2F;SMTP&#x2F;IMAP”。 开启服务：确保 IMAP&#x2F;SMTP服务 这一项是 “已开启” 状态。 获取授权码：点击“授权码”管理，根据提示">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2025-07-30T12:54:59.000Z">
<meta property="article:modified_time" content="2025-07-30T13:17:56.309Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="SMTP">
<meta property="article:tag" content="Ubuntu">
<meta property="article:tag" content="邮箱">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css">

<meta name="generator" content="Hexo 7.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/atom.xml" title="RSS Feed"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="Search"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-163邮箱邮件通知功能配置" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2025/07/30/163%E9%82%AE%E7%AE%B1%E9%82%AE%E4%BB%B6%E9%80%9A%E7%9F%A5%E5%8A%9F%E8%83%BD%E9%85%8D%E7%BD%AE/" class="article-date">
  <time class="dt-published" datetime="2025-07-30T12:54:59.000Z" itemprop="datePublished">2025-07-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      163邮箱邮件通知功能配置
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="第一阶段：在163邮箱网页端获取“授权码”"><a href="#第一阶段：在163邮箱网页端获取“授权码”" class="headerlink" title="第一阶段：在163邮箱网页端获取“授权码”"></a>第一阶段：在163邮箱网页端获取“授权码”</h3><p>这是所有终端操作的前提，目的是获取一个用于第三方客户端登录的专用密码。</p>
<ol>
<li><strong>登录邮箱</strong>：在浏览器中访问 <code>mail.163.com</code> 并登录您的账户。</li>
<li><strong>进入设置</strong>：点击页面顶部的 “设置” -&gt; <strong>“POP3&#x2F;SMTP&#x2F;IMAP”</strong>。</li>
<li><strong>开启服务</strong>：确保 <code>IMAP/SMTP服务</code> 这一项是 “已开启” 状态。</li>
<li><strong>获取授权码</strong>：点击“授权码”管理，根据提示（通常是手机App扫码验证）获取一个<strong>16位的授权码</strong>。<ul>
<li>请务必复制并保存好这个授权码，它将作为您在终端配置中的“密码”。</li>
</ul>
</li>
</ol>
<hr>
<h3 id="第二阶段：在Ubuntu终端配置msmtp客户端"><a href="#第二阶段：在Ubuntu终端配置msmtp客户端" class="headerlink" title="第二阶段：在Ubuntu终端配置msmtp客户端"></a>第二阶段：在Ubuntu终端配置msmtp客户端</h3><p>这一步是让您的系统学会如何通过163服务器发送邮件。</p>
<ol>
<li><strong>安装软件包</strong>：<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> apt update</span><br><span class="line"><span class="built_in">sudo</span> apt install msmtp msmtp-mta mailutils</span><br></pre></td></tr></table></figure></li>
<li><strong>创建并编辑配置文件</strong>：<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nano ~/.msmtprc</span><br></pre></td></tr></table></figure></li>
<li><strong>填入163邮箱专属配置</strong>：将以下经过验证的最终配置模板<strong>完整地复制粘贴</strong>到编辑器中。<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 设置所有账户的默认值</span></span><br><span class="line">defaults</span><br><span class="line">auth           on</span><br><span class="line">tls            on</span><br><span class="line">tls_starttls   on</span><br><span class="line">tls_trust_file /etc/ssl/certs/ca-certificates.crt</span><br><span class="line">logfile        ~/.msmtp.log</span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置您的163邮箱账户</span></span><br><span class="line">account        163</span><br><span class="line">host           smtp.163.com</span><br><span class="line"><span class="comment"># 关键：使用加密端口465，并关闭STARTTLS，这是最稳定的连接方式</span></span><br><span class="line">port           465</span><br><span class="line">tls_starttls   off</span><br><span class="line">from           &quot;您的显示名称 &lt;your-email@163.com&gt;&quot;</span><br><span class="line">user           your-email@163.com</span><br><span class="line"><span class="comment"># 粘贴您在第一阶段获取的163邮箱授权码</span></span><br><span class="line">password       your_163_authorization_code</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将163邮箱设为默认使用的账户</span></span><br><span class="line">account default : 163</span><br></pre></td></tr></table></figure>
<ul>
<li>请务必将 <code>from</code>, <code>user</code>, <code>password</code> 字段替换为您自己的信息。</li>
</ul>
</li>
<li><strong>设置严格的文件权限（关键安全步骤）</strong>：<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">chmod</span> 600 ~/.msmtprc</span><br></pre></td></tr></table></figure></li>
</ol>
<hr>
<h3 id="第三阶段：创建并固化notify快捷命令"><a href="#第三阶段：创建并固化notify快捷命令" class="headerlink" title="第三阶段：创建并固化notify快捷命令"></a>第三阶段：创建并固化notify快捷命令</h3><p>这一步将复杂的命令封装成一个简单易用的快捷方式。</p>
<ol>
<li><strong>编辑Shell配置文件 <code>~/.bashrc</code></strong>：<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nano ~/.bashrc</span><br></pre></td></tr></table></figure></li>
<li><strong>将notify函数代码粘贴到文件末尾</strong>：将以下最终版本的函数代码，完整地粘贴到 <code>~/.bashrc</code> 文件的最末尾。<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">notify</span></span>() &#123;</span><br><span class="line">    <span class="comment"># 执行传递给 notify 的所有参数，即您的原始命令</span></span><br><span class="line">    <span class="string">&quot;<span class="variable">$@</span>&quot;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 获取上一个命令的成功/失败状态码</span></span><br><span class="line">    <span class="built_in">local</span> exit_code=$?</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 将命令本身作为字符串，用于邮件内容</span></span><br><span class="line">    <span class="built_in">local</span> command_str=<span class="string">&quot;$*&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 定义发件人邮箱，这必须与您在msmtp中配置的user一致</span></span><br><span class="line">    <span class="built_in">local</span> sender_email=<span class="string">&quot;your-email@163.com&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$exit_code</span> -eq 0 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="comment"># 成功时发送的邮件</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">&quot;命令已于 <span class="subst">$(date)</span> 成功完成:</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;<span class="variable">$command_str</span>&#x27;&quot;</span> | mail -s <span class="string">&quot;✅ 任务成功&quot;</span> -r <span class="string">&quot;<span class="variable">$sender_email</span>&quot;</span> <span class="string">&quot;<span class="variable">$sender_email</span>&quot;</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="comment"># 失败时发送的邮件</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">&quot;命令已于 <span class="subst">$(date)</span> 失败 (退出码: <span class="variable">$exit_code</span>):</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;<span class="variable">$command_str</span>&#x27;&quot;</span> | mail -s <span class="string">&quot;❌ 任务失败&quot;</span> -r <span class="string">&quot;<span class="variable">$sender_email</span>&quot;</span> <span class="string">&quot;<span class="variable">$sender_email</span>&quot;</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>请务必将 <code>local sender_email=&quot;...&quot;</code> 这一行中的邮箱地址换成您自己的163邮箱。</li>
</ul>
</li>
<li><strong>激活配置</strong>：保存文件后，执行 <code>source ~/.bashrc</code> 或重开一个终端，让 <code>notify</code> 命令生效。</li>
</ol>
<hr>
<h3 id="第四阶段：如何使用"><a href="#第四阶段：如何使用" class="headerlink" title="第四阶段：如何使用"></a>第四阶段：如何使用</h3><p>现在，您可以像使用 <code>sudo</code> 一样，在任何耗时命令前加上 <code>notify</code> 来享受自动化邮件提醒了。</p>
<p><strong>示例</strong>：</p>
<pre><code class="language-bash">notify petalinux-build --sdk
notify tar -czf big_backup.tar.gz /path/to/large_folder
</code></pre>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2025/07/30/163%E9%82%AE%E7%AE%B1%E9%82%AE%E4%BB%B6%E9%80%9A%E7%9F%A5%E5%8A%9F%E8%83%BD%E9%85%8D%E7%BD%AE/" data-id="cmdpzrpke0000urr64ck54p8s" data-title="163邮箱邮件通知功能配置" class="article-share-link"><span class="fa fa-share">Share</span></a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SMTP/" rel="tag">SMTP</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Ubuntu/" rel="tag">Ubuntu</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%82%AE%E7%AE%B1/" rel="tag">邮箱</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/2025/07/30/hello-world/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Hello World</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SMTP/" rel="tag">SMTP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ubuntu/" rel="tag">Ubuntu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%82%AE%E7%AE%B1/" rel="tag">邮箱</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Linux/" style="font-size: 10px;">Linux</a> <a href="/tags/SMTP/" style="font-size: 10px;">SMTP</a> <a href="/tags/Ubuntu/" style="font-size: 10px;">Ubuntu</a> <a href="/tags/%E9%82%AE%E7%AE%B1/" style="font-size: 10px;">邮箱</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2025/07/">July 2025</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2025/07/30/163%E9%82%AE%E7%AE%B1%E9%82%AE%E4%BB%B6%E9%80%9A%E7%9F%A5%E5%8A%9F%E8%83%BD%E9%85%8D%E7%BD%AE/">163邮箱邮件通知功能配置</a>
          </li>
        
          <li>
            <a href="/2025/07/30/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2025 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.6.4.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>